package com.plian.system.service.sys.bigdata.BulletinService;


import com.plian.Tools.UuidUtil;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.entity.pm.propertyinformation.PropertyTime;
import com.plian.system.mapper.fr.bigdata.BulletinfoMapper;
import lombok.AllArgsConstructor;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author huzb
 * @create 2020-10-23 9:02
 */

@Service
@AllArgsConstructor
public class BulletinOutForService {

    BulletinfoMapper bulletinfoMapper;

    BulletinfoService bulletinfoService;

    public List<PageData> insertBasicInfo(PropertyTime propertyTime){
        int i = 0;
        JSONObject jsonObject = JSONObject.fromObject(propertyTime.toString());
        String startTime = jsonObject.getString("startTime");
        String op = "";
        if ("1949-01-01 00:00:00".equals(startTime)){
            op = "1";
        }else {
            op = "1";
        }
        List<PageData> listByDateRange = bulletinfoService.findListByDateRange(propertyTime.toString());
        List<PageData> list = new ArrayList<>();
        for (PageData pd : listByDateRange){
            Set set = pd.keySet();
            Iterator iterator = set.iterator();
            while (iterator.hasNext()){
                String key = (String)iterator.next();
                String value = pd.getString(key);
                if (value == null){
                    pd.put(key,"0");
                }else {
                    pd.put(key,value);
                }
            }
            pd.put("id", UuidUtil.get32UUID());
            pd.put("op",op);
            list.add(pd);
        }
        return list;
    }

//    @DS("slave_1")
    public void insertBulletInfo(List<PageData> list){
        for (PageData pd :list){
            bulletinfoMapper.insertBasicInfo(pd);
        }
    }
//    public static void main(String[] args) {
//        PropertyTime propertyTime = new PropertyTime("2020-08-01", "2020-08-02");
//        BulletinfoService bulletinfoService = new BulletinfoService();
//        bulletinfoService.insertBasicInfo(propertyTime);
//        System.out.println();
//    }
}
